<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--conf
<sample in_favorites="true">
	<product version="1.0" edition="std"/>
	<modifications>
		<modified date="080205"/>
	</modifications>
<sampledescription><![CDATA[ ]]></sampledescription></sample>
 --> 

<html>
<head>
	<title>Drag-and-drop between DataView and Tree</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<link rel="stylesheet" type="text/css" href="../../../codebase/dhtmlx.css"/>
	<script src="../../../codebase/dhtmlx.js"></script>
<body>
	<h1>Drag-and-drop between DataView and Tree</h1>
	<table border="0" cellspacing="5" cellpadding="5">
		<tr><td>
			<div id="data_container1" style="border:1px solid #A4BED4; background-color:white;width:240px;height:396px;"></div>				
		</td><td>
			
		</td><td>
			<div id="data_container2" style="border:1px solid #A4BED4; background-color:white;width:400px;height:396px;"></div>				
		</td></tr>				
	</table>

	<script>
		dhtmlx.compat("dnd");
				
		data = new dhtmlXDataView({
			container:"data_container1",
			type:{
				template:"#Package# : #Version#<br/>#Maintainer#",
				padding:5,
				height:40
			},
			drag:true,
			select:true
		});
		data.load("../common/data.xml");
		
		
		tree=new dhtmlXTreeObject("data_container2","100%","100%",0);
		tree.setSkin('dhx_skyblue');
		tree.enableDragAndDrop(true);
		tree.setImagePath("../../../codebase/imgs/dhxtree_skyblue/");
		tree.loadXML("../../dhtmlxTree/common/tree.xml");
		
		
		
		//drag from tree into the dataview
		data.attachEvent("onBeforeDrop",function(context){
			if (context.from == tree){
				this.add({
					Package:context.from.getItemText(context.source),
					Version:"1.0",
					Maintainer:"not defined"
				}, this.indexById(context.target||this.first()));
				context.from.deleteItem(context.source);
				return false;
			}
			return true;
		})
		
		//drag from dataview into the tree
		tree.attachEvent("onDrag",function(sid,tid,tindex, sobj,tobj){
			if (sobj.object && sobj.object == data){
				if (tid != 0)
					tree.insertNewNext(tid, sid, data.get(sid).Package );
				else
					tree.insertNewChild(tid, sid, data.get(sid).Package );
				data.remove(sid);
				return false;
			}
			return true;
		})
		
	</script>
</body>
</html>

